<?php 
	if(isset($message)){
		echo $message;
	} else {
?>
<h1>Dependents</h1>
<?php echo form_open('user/dependents');?>

<table>
	<?php if(isset($dependent)){?>
	<tr>
		<td colspan="2">
			<table>
				<tr>
					<td>Firstname:</td>
					<td><input type="text" name="dependent_first_name[]" value="<?php echo $dependent->first_name?>">
					<input type="hidden" name="dependent_id[]" value="<?php echo $dependent->id?>">
					</td>
				</tr>
				<tr>
					<td>Lastname:</td>
					<td><input type="text" name="dependent_last_name[]" value="<?php echo $dependent->last_name?>"></td>
				</tr>
				<tr>
					<td>Middlename:</td>
					<td><input type="text" name="dependent_middle_name[]" value="<?php echo $dependent->middle_name?>"></td>
				</tr>
				<tr>
					<td>Date of Birth:</td>
					<td>
						<input type="text" id="dependent_birth_date" name="dependent_birth_date[]" value="<?php echo $dependent->birth_date?>">
					</td>
				</tr>
				<tr>
					<td>Gender:</td>
					<td>
						<select name="dependent_gender[]" value="<?php echo $dependent->gender?>">
							<option value="Male">Male</option>
							<option value="Female">Female</option>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>Type:</td>
					<td>
						<select name="dependent_type[]">
							<option value="SPOUSE">Spouse</option>
							<option value="CHILD">Child</option>
							<option value="PARENT">Parent</option>
						</select>
					
					</td>
				</tr>
			</table>
		</td>
		
	</tr>
	<?php } else { ?>
	<tr>
		<td colspan="2">
			<table>
				<tr>
					<td>Firstname:</td>
					<td><input type="text" name="dependent_first_name[]">
					<input type="hidden" name="dependent_id[]" value="1">
					</td>
				</tr>
				<tr>
					<td>Lastname:</td>
					<td><input type="text" name="dependent_last_name[]"></td>
				</tr>
				<tr>
					<td>Middlename:</td>
					<td><input type="text" name="dependent_middle_name[]"></td>
				</tr>
				<tr>
					<td>Date of Birth:</td>
					<td>
						<input type="text" name="dependent_birth_date[]" id="dependent_birth_date">
					</td>
				</tr>
				<tr>
					<td>Gender:</td>
					<td>
						<select name="dependent_gender[]">
							<option value="Male">Male</option>
							<option value="Female">Female</option>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>Type:</td>
					<td>
						<select name="dependent_type[]">
							<option value="SPOUSE">Spouse</option>
							<option value="CHILD">Child</option>
							<option value="PARENT">Parent</option>
						</select>
					
					</td>
				</tr>
			</table>
		</td>
		
	</tr>
	<!-- <tr>
		<td colspan="2">
			<table>
				<tr>
					<td>Firstname:</td>
					<td><input type="text" name="dependent_first_name[]">
					<input type="hidden" name="dependent_id[]" value="2">
					</td>
				</tr>
				<tr>
					<td>Lastname:</td>
					<td><input type="text" name="dependent_last_name[]"></td>
				</tr>
				<tr>
					<td>Middlename:</td>
					<td><input type="text" name="dependent_middle_name[]"></td>
				</tr>
				<tr>
					<td>Date of Birth:</td>
					<td>
						<input type="text" name="dependent_birth_date[]">
					</td>
				</tr>
				<tr>
					<td>Gender:</td>
					<td>
						<select name="dependent_gender[]">
							<option value="Male">Male</option>
							<option value="Female">Female</option>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>Type:</td>
					<td>
						<select name="dependent_type[]">
							<option value="SPOUSE">Spouse</option>
							<option value="CHILD">Child</option>
							<option value="PARENT">Parent</option>
						</select>
					
					</td>
				</tr>
			</table>
		</td>
		
	</tr>
	<tr>
		<td colspan="2">
			<table>
				<tr>
					<td>Firstname:</td>
					<td><input type="text" name="dependent_first_name[]">
					<input type="hidden" name="dependent_id[]" value="3">
					</td>
				</tr>
				<tr>
					<td>Lastname:</td>
					<td><input type="text" name="dependent_last_name[]"></td>
				</tr>
				<tr>
					<td>Middlename:</td>
					<td><input type="text" name="dependent_middle_name[]"></td>
				</tr>
				<tr>
					<td>Date of Birth:</td>
					<td>
						<input type="text" name="dependent_birth_date[]">
					</td>
				</tr>
				<tr>
					<td>Gender:</td>
					<td>
						<select name="dependent_gender[]">
							<option value="Male">Male</option>
							<option value="Female">Female</option>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>Type:</td>
					<td>
						<select name="dependent_type[]">
							<option value="SPOUSE">Spouse</option>
							<option value="CHILD">Child</option>
							<option value="PARENT">Parent</option>
						</select>
					
					</td>
				</tr>
			</table>
		</td>
		
	</tr>
	 -->
	<?php } ?>
	<tr>
		<td colspan="2">
		<?php echo form_hidden("user_id", $user_id);?>
		<input type="submit" name="submit" value="Register"></td>
	</tr>
	
</table>
<?php } ?>
<?php echo form_close();?>
<script>
$(document).ready(function(){
	<?php if(isset($message)):?>
		setTimeout( function() {
			tr_count = parent.$('#dependents_table tr').length;
			css = (tr_count % 2)?'odd':'even';
			tr = "<tr id='tr_dependent_<?php echo $dependent['id']?>' class='" + css +"'><td>" + "<?php echo $dependent['full_name']?>" + "</td><td>" + "<?php echo $dependent['birth_date']?>" + "</td><td>";
			tr +="<?php echo $dependent['gender']?>" + "</td><td>" + "<?php echo $dependent['type']?>" + "</td><td>";
			tr += "<a href='javascript:;' onClick='editData(\"<?php echo $dependent['id']?>\",\"dependent\")'>Edit</a> | <a href='javascript:;' onclick='deleteData(\"<?php echo $dependent['id']?>\",\"dependent\")' >Delete</a>";
			tr += "</td></tr>";
			parent.$('#dependents_table').append(tr);
			parent.$.fancybox.close();
		}, 2000 );
	<?php endif;?>

	$("#dependent_birth_date").datepicker();
	$("#dependent_birth_date").datepicker( "option", "dateFormat", 'yy-mm-dd' );

})

function reloadPage(){
	
}

</script>
